package cn.lintcode;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author labvi
 * @version 1.0.0
 */
public class LargestNum2 {
    public String largestNumber(String[] nums) {
        Arrays.parallelSort(nums,new NumbersComparator());
//        Arrays.sort(nums, new NumbersComparator());
       /* StringBuilder sb = new StringBuilder();
        for (String num : nums) {
            sb.append(num);
        }*/
        String res = String.join("",nums);
        return res.charAt(0) == '0'?"0":res;
    }

    public static void main(String[] args) {

        long l = System.currentTimeMillis();
        LargestNum2 largestNum2 = new LargestNum2();
        System.out.println(largestNum2.largestNumber(new String[]{"12","56","12","78"}));
        System.out.println(System.currentTimeMillis() - l);
    }
}

class NumbersComparator implements Comparator<String> {
    @Override
    public int compare(String s1, String s2) {
        return (s2 + s1).compareTo(s1 + s2);
    }
}
